////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2017-2018 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// THIS IS AUTO-GENERATED CODE.  PLEASE DO NOT EDIT (File bug reports against tools).
///
/// Auto-generated by: ParameterParser V1.1.4
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file  camxmoduleconfig.cpp
/// @brief Auto-generated Chromatix parameter file
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "camxmoduleconfig.h"
#include "parametersetmanager.h"

CAMX_NAMESPACE_BEGIN

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Default Constructor
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CameraModuleDataClass::CameraModuleDataClass(
    const CHAR* name)
    : ParameterModule(name, MAJOR, MINOR, PATCH, 0, 0, 0, 0)
{
    PARAMETER_INITIALIZE(SymbolTableID);
    PARAMETER_INITIALIZE(module_version);
    PARAMETER_INITIALIZE(moduleGroup);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Constructor
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CameraModuleDataClass::CameraModuleDataClass(
    const CHAR* name,
    UINT32 modeId,
    UINT16 mode,
    UINT16 subMode,
    UINT32 group)
    : ParameterModule(name, MAJOR, MINOR, PATCH, modeId, mode, subMode, group)
{
    PARAMETER_INITIALIZE(SymbolTableID);
    PARAMETER_INITIALIZE(module_version);
    PARAMETER_INITIALIZE(moduleGroup);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Destructor
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CameraModuleDataClass::~CameraModuleDataClass()
{
    UnloadCameraModuleData(this);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// GetName
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const CHAR* CameraModuleDataClass::GetName(
    const CHAR* type)
{
    const CHAR* name = type;
    CHAR temp[ParameterFileSymbolTableEntry::TYPE_LEN + 1];
    if (PARAMETER_STRCMP(type, ParameterFileSymbolTableEntry::GetType(temp, "cameraModuleData")) == 0)
    {
        name = "cameraModuleData";
    }
    return name;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load CSIInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL CameraModuleDataClass::LoadCSIInformation(
    ParameterFileSymbolTableEntry* entry,
    CSIInformation* structure)
{
    BOOL result = TRUE;

    // Reading structure->laneAssign from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->laneAssignExists);
        structure->laneAssignID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->laneAssignExists)
        {
            result = result && pointerEntry1->ReadUInt16(&structure->laneAssign);
        }
        else
        {
            PARAMETER_INITIALIZE(structure->laneAssign);
        }
    }

    // Reading structure->isComboMode from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->isComboModeExists);
        structure->isComboModeID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->isComboModeExists)
        {
            result = result && pointerEntry1->ReadUInt8(&structure->isComboMode);
        }
        else
        {
            PARAMETER_INITIALIZE(structure->isComboMode);
        }
    }

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load LensInformation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL CameraModuleDataClass::LoadLensInformation(
    ParameterFileSymbolTableEntry* entry,
    LensInformation* structure)
{
    BOOL result = TRUE;
    result = result && entry->ReadDouble(&structure->focalLength);
    result = result && entry->ReadDouble(&structure->fNumber);
    result = result && entry->ReadDouble(&structure->minFocusDistance);
    result = result && entry->ReadDouble(&structure->maxFocusDistance);
    result = result && entry->ReadDouble(&structure->horizontalViewAngle);
    result = result && entry->ReadDouble(&structure->verticalViewAngle);

    // Reading structure->maxRollDegree from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->maxRollDegreeExists);
        structure->maxRollDegreeID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->maxRollDegreeExists)
        {
            result = result && pointerEntry1->ReadDouble(&structure->maxRollDegree);
        }
        else
        {
            PARAMETER_INITIALIZE(structure->maxRollDegree);
        }
    }

    // Reading structure->maxPitchDegree from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->maxPitchDegreeExists);
        structure->maxPitchDegreeID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->maxPitchDegreeExists)
        {
            result = result && pointerEntry1->ReadDouble(&structure->maxPitchDegree);
        }
        else
        {
            PARAMETER_INITIALIZE(structure->maxPitchDegree);
        }
    }

    // Reading structure->maxYawDegree from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->maxYawDegreeExists);
        structure->maxYawDegreeID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->maxYawDegreeExists)
        {
            result = result && pointerEntry1->ReadDouble(&structure->maxYawDegree);
        }
        else
        {
            PARAMETER_INITIALIZE(structure->maxYawDegree);
        }
    }

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load ModuleConfiguration
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL CameraModuleDataClass::LoadModuleConfiguration(
    ParameterFileSymbolTableEntry* entry,
    ModuleConfiguration* structure)
{
    BOOL result = TRUE;
    result = result && entry->ReadUInt16(&structure->cameraId);

    // Reading structure->moduleName from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->moduleNameExists);
        structure->moduleNameID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->moduleNameExists)
        {

            // Reading structure->moduleName from the symbol table
            {
                result = result && pointerEntry1->ReadUInt32(&structure->moduleNameExists);
                structure->moduleNameID = entry->ID;
                ParameterFileSymbolTableEntry* pointerEntry3 = pointerEntry1->Table->ReadPointerEntry(pointerEntry1);
                result = result && pointerEntry3 != NULL;
                structure->moduleName = NULL;
                if (result)
                {
                    pointerEntry3->ReadString(&structure->moduleName, structure->moduleNameExists);
                }
            }
        }
        else
        {
            PARAMETER_INITIALIZE(structure->moduleName);
        }
    }

    // Reading structure->sensorName from the symbol table
    {
        UINT32 sensorNameCount = 0;
        result = result && entry->ReadUInt32(&sensorNameCount);
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        structure->sensorName = NULL;
        if (result)
        {
            pointerEntry1->ReadString(&structure->sensorName, sensorNameCount);
        }
    }

    // Reading structure->sensorSlaveAddress from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->sensorSlaveAddressExists);
        structure->sensorSlaveAddressID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->sensorSlaveAddressExists)
        {
            result = result && pointerEntry1->ReadUInt16(&structure->sensorSlaveAddress);
        }
        else
        {
            PARAMETER_INITIALIZE(structure->sensorSlaveAddress);
        }
    }

    // Reading structure->sensorI2CFrequencyMode from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->sensorI2CFrequencyModeExists);
        structure->sensorI2CFrequencyModeID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->sensorI2CFrequencyModeExists)
        {
            structure->sensorI2CFrequencyMode = (I2CFrequencyMode)pointerEntry1->ReadEnum(&result);
        }
        else
        {
            PARAMETER_INITIALIZE(structure->sensorI2CFrequencyMode);
        }
    }

    // Reading structure->actuatorName from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->actuatorNameExists);
        structure->actuatorNameID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->actuatorNameExists)
        {

            // Reading structure->actuatorName from the symbol table
            {
                result = result && pointerEntry1->ReadUInt32(&structure->actuatorNameExists);
                structure->actuatorNameID = entry->ID;
                ParameterFileSymbolTableEntry* pointerEntry3 = pointerEntry1->Table->ReadPointerEntry(pointerEntry1);
                result = result && pointerEntry3 != NULL;
                structure->actuatorName = NULL;
                if (result)
                {
                    pointerEntry3->ReadString(&structure->actuatorName, structure->actuatorNameExists);
                }
            }
        }
        else
        {
            PARAMETER_INITIALIZE(structure->actuatorName);
        }
    }

    // Reading structure->oisName from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->oisNameExists);
        structure->oisNameID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->oisNameExists)
        {

            // Reading structure->oisName from the symbol table
            {
                result = result && pointerEntry1->ReadUInt32(&structure->oisNameExists);
                structure->oisNameID = entry->ID;
                ParameterFileSymbolTableEntry* pointerEntry3 = pointerEntry1->Table->ReadPointerEntry(pointerEntry1);
                result = result && pointerEntry3 != NULL;
                structure->oisName = NULL;
                if (result)
                {
                    pointerEntry3->ReadString(&structure->oisName, structure->oisNameExists);
                }
            }
        }
        else
        {
            PARAMETER_INITIALIZE(structure->oisName);
        }
    }

    // Reading structure->eepromName from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->eepromNameExists);
        structure->eepromNameID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->eepromNameExists)
        {

            // Reading structure->eepromName from the symbol table
            {
                result = result && pointerEntry1->ReadUInt32(&structure->eepromNameExists);
                structure->eepromNameID = entry->ID;
                ParameterFileSymbolTableEntry* pointerEntry3 = pointerEntry1->Table->ReadPointerEntry(pointerEntry1);
                result = result && pointerEntry3 != NULL;
                structure->eepromName = NULL;
                if (result)
                {
                    pointerEntry3->ReadString(&structure->eepromName, structure->eepromNameExists);
                }
            }
        }
        else
        {
            PARAMETER_INITIALIZE(structure->eepromName);
        }
    }

    // Reading structure->flashName from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->flashNameExists);
        structure->flashNameID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->flashNameExists)
        {

            // Reading structure->flashName from the symbol table
            {
                result = result && pointerEntry1->ReadUInt32(&structure->flashNameExists);
                structure->flashNameID = entry->ID;
                ParameterFileSymbolTableEntry* pointerEntry3 = pointerEntry1->Table->ReadPointerEntry(pointerEntry1);
                result = result && pointerEntry3 != NULL;
                structure->flashName = NULL;
                if (result)
                {
                    pointerEntry3->ReadString(&structure->flashName, structure->flashNameExists);
                }
            }
        }
        else
        {
            PARAMETER_INITIALIZE(structure->flashName);
        }
    }

    // Reading structure->chromatixName from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->chromatixNameExists);
        structure->chromatixNameID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->chromatixNameExists)
        {

            // Reading structure->chromatixName from the symbol table
            {
                result = result && pointerEntry1->ReadUInt32(&structure->chromatixNameExists);
                structure->chromatixNameID = entry->ID;
                ParameterFileSymbolTableEntry* pointerEntry3 = pointerEntry1->Table->ReadPointerEntry(pointerEntry1);
                result = result && pointerEntry3 != NULL;
                structure->chromatixName = NULL;
                if (result)
                {
                    pointerEntry3->ReadString(&structure->chromatixName, structure->chromatixNameExists);
                }
            }
        }
        else
        {
            PARAMETER_INITIALIZE(structure->chromatixName);
        }
    }
    structure->position = (CameraPosition)entry->ReadEnum(&result);
    result = result && LoadCSIInformation(entry, &structure->CSIInfo);
    result = result && LoadLensInformation(entry, &structure->lensInfo);

    // Reading structure->pdafName from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->pdafNameExists);
        structure->pdafNameID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result && structure->pdafNameExists)
        {

            // Reading structure->pdafName from the symbol table
            {
                result = result && pointerEntry1->ReadUInt32(&structure->pdafNameExists);
                structure->pdafNameID = entry->ID;
                ParameterFileSymbolTableEntry* pointerEntry3 = pointerEntry1->Table->ReadPointerEntry(pointerEntry1);
                result = result && pointerEntry3 != NULL;
                structure->pdafName = NULL;
                if (result)
                {
                    pointerEntry3->ReadString(&structure->pdafName, structure->pdafNameExists);
                }
            }
        }
        else
        {
            PARAMETER_INITIALIZE(structure->pdafName);
        }
    }

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load ModuleGroup
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL CameraModuleDataClass::LoadModuleGroup(
    ParameterFileSymbolTableEntry* entry,
    ModuleGroup* structure)
{
    BOOL result = TRUE;

    // Reading structure->moduleConfiguration from the symbol table
    {
        result = result && entry->ReadUInt32(&structure->moduleConfigurationCount);
        structure->moduleConfigurationID = entry->ID;
        ParameterFileSymbolTableEntry* pointerEntry1 = entry->Table->ReadPointerEntry(entry);
        result = result && pointerEntry1 != NULL;
        if (result)
        {
            structure->moduleConfiguration   = PARAMETER_NEW ModuleConfiguration[structure->moduleConfigurationCount];
        }
        if (!result || structure->moduleConfiguration == NULL)
        {
            structure->moduleConfigurationCount = 0;
        }
        for (UINT32 i = 0; result && i < structure->moduleConfigurationCount; i++)
        {
            result = result && LoadModuleConfiguration(pointerEntry1, &structure->moduleConfiguration[i]);
        }
    }

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load CameraModuleData
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL CameraModuleDataClass::LoadCameraModuleData(
    ParameterFileSymbolTableEntry* entry,
    CameraModuleData* structure)
{
    BOOL result = TRUE;
    result = result && Loadmodule_versionStruct(entry, &structure->module_version);
    result = result && LoadModuleGroup(entry, &structure->moduleGroup);

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load module_versionStruct
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL CameraModuleDataClass::Loadmodule_versionStruct(
    ParameterFileSymbolTableEntry* entry,
    CameraModuleData::module_versionStruct* structure)
{
    BOOL result = TRUE;
    result = result && entry->ReadInt32(&structure->major_revision);
    result = result && entry->ReadInt32(&structure->minor_revision);
    result = result && entry->ReadInt32(&structure->incr_revision);

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload ModuleConfiguration
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CameraModuleDataClass::UnloadModuleConfiguration(
    ModuleConfiguration* structure)
{
    PARAMETER_DELETE[] structure->moduleName;
    PARAMETER_DELETE[] structure->sensorName;
    PARAMETER_DELETE[] structure->actuatorName;
    PARAMETER_DELETE[] structure->oisName;
    PARAMETER_DELETE[] structure->eepromName;
    PARAMETER_DELETE[] structure->flashName;
    PARAMETER_DELETE[] structure->chromatixName;
    PARAMETER_DELETE[] structure->pdafName;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload ModuleGroup
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CameraModuleDataClass::UnloadModuleGroup(
    ModuleGroup* structure)
{
    for (UINT32 i = 0; i < structure->moduleConfigurationCount; i++)
    {
        UnloadModuleConfiguration(&structure->moduleConfiguration[i]);
    }
    PARAMETER_DELETE[] structure->moduleConfiguration;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload CameraModuleData
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CameraModuleDataClass::UnloadCameraModuleData(
    CameraModuleData* structure)
{
    UnloadModuleGroup(&structure->moduleGroup);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Parse symbol table entry, and return a new object
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ParameterModule* CameraModuleDataClass::Parse(
    ParameterSetManager* manager,
    ParameterFileSymbolTableEntry* entry) const
{
    CameraModuleDataClass* cls = NULL;

    if (PARAMETER_STRCMP(Type, entry->Type) == 0 && Major == entry->Major &&
        Minor == entry->Minor && Patch == entry->Patch)
    {
        cls = PARAMETER_NEW CameraModuleDataClass(GetName(entry->Type), 
            entry->ModeId, entry->Mode, entry->SubMode, entry->Group);
        if (cls != NULL)
        {
            BOOL result = TRUE;

            cls->SymbolTableID = entry->ID;
            cls->ID            = entry->ID;

            result = result && LoadCameraModuleData(entry, cls);

            if (!result)
            {
                PARAMETER_DELETE cls;
                cls = NULL;
            }
        }
    }
    return (ParameterModule*)cls;
}


CAMX_NAMESPACE_END
